﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Mimi.Converters
{
    public class NumericStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return "0";
            }

            double number = 0;
            if (double.TryParse(value.ToString(), out number))
            {
                if(value.ToString().Contains("."))
                {
                    return value;
                }

                return number.ToString("N0", CultureInfo.CreateSpecificCulture("en-US"));
            }

            return "0";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value.ToString();
        }
    }
}
